//
//  NetPostClass.m
//  TestAsiPost
//
//  Created by wrt on 14-9-4.
//  Copyright (c) 2014年 wrtsoft. All rights reserved.
//

#import "NetPostClass.h"
#import "ASIFormDataRequest.h"
#import "ASIHTTPRequest.h"

//全局域名
static NSString *netUrlStr = @"web.wrtrd.net:8080";
//static NSString *netUrlStr = @"192.168.56.201:8080";
//static NSString *netUrlStr = @"182.92.195.120:8080";
//post操作对象的单例
static NetPostClass *shareNetPostClass = nil;

@implementation NetPostClass

@synthesize delegate = _delegate;

//初始化方法
+ (NetPostClass *)shareNetPostClass
{
    @synchronized(self)
    {
        if (shareNetPostClass == nil)
        {
            shareNetPostClass = [[self alloc] init];
        }
    }
    return shareNetPostClass;
}

//注册
- (void)postRegistInfoWithUserName:(NSString *)username andPassWord:(NSString *)password andUserCode:(NSString *)userCode andName:(NSString *)name andSex:(NSString *)sex andCredentialsTypeId:(NSString *)credentialsTypeId andCredentialsNum:(NSString *)credentialsNum andBirthday:(NSString *)birthday andEmail:(NSString *)email andRegisterTime:(NSString *)registerTime andRemark:(NSString *)remark andAddress:(NSString *)address andTelePhone:(NSString *)telePhone andVerification:(NSString *)verification
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/tnserver/user",netUrlStr]];
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"Content-Type" value:@"text/json; encoding=utf-8"];
    [request addRequestHeader:@"Accept" value:@"text/json"];
    
    [request setRequestMethod:@"PUT"];
    [request setUsername:@"wrt"];
    [request setPassword:@"wrt12"];
    
    NSMutableDictionary *registDic = [[NSMutableDictionary alloc] init];
    [registDic setObject:username forKey:@"userName"];
    [registDic setObject:password forKey:@"password"];
    [registDic setObject:@"123456" forKey:@"userCode"];
    [registDic setObject:@"AASSDD" forKey:@"name"];
    [registDic setObject:[NSNumber numberWithInt:0] forKey:@"sex"];
    [registDic setObject:[NSNumber numberWithInt:0] forKey:@"credentialsTypeId"];
    [registDic setObject:[NSNumber numberWithInt:123456] forKey:@"credentialsNum"];
    [registDic setObject:@"" forKey:@"birthday"];
    [registDic setObject:@"" forKey:@"email"];
    [registDic setObject:@"" forKey:@"registerTime"];
    [registDic setObject:@"" forKey:@"address"];
    [registDic setObject:@"" forKey:@"telePhone"];
    [registDic setObject:@"" forKey:@"remark"];
    [registDic setObject:verification forKey:@"verification"];
    
    
    NSDictionary *tempDic = [[NSDictionary alloc] initWithObjectsAndKeys:registDic, @"register" , nil];

    if ([NSJSONSerialization isValidJSONObject:tempDic])
    {
        NSError *error;
        NSData *registerData = [NSJSONSerialization dataWithJSONObject:tempDic options:NSJSONWritingPrettyPrinted error:&error];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:registerData];
        [request setPostBody:tempJsonData];
        NSLog(@"Register JSON:%@",[[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding]);
        request.tag = 1;
        [request setDelegate:self];
        [request startAsynchronous];
    }
}

//登录
- (void)postLoginInfoWithUserName:(NSString *)username andpassWord:(NSString *)password andDev:(NSString *)ver andCa:(NSString *)ca
{
    
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/tnserver/user",netUrlStr]];
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"Content-Type" value:@"text/json; encoding=utf-8"];
    [request addRequestHeader:@"Accept" value:@"text/json"];
    
    [request setRequestMethod:@"POST"];
    [request setUsername:@"wrt"];
    [request setPassword:@"wrt12"];
    
    NSMutableDictionary *loginDic = [[NSMutableDictionary alloc] init];
    [loginDic setObject:username forKey:@"userName"];
    [loginDic setObject:password forKey:@"password"];
    
    NSMutableDictionary *subLoginDic = [[NSMutableDictionary alloc] init];
    [subLoginDic setObject:ver forKey:@"dev"];
    [subLoginDic setObject:ca forKey:@"ca"];
    
    [loginDic setObject:subLoginDic forKey:@"dev-info"];
    
    NSDictionary *tempDic = [[NSDictionary alloc] initWithObjectsAndKeys:loginDic, @"login" , nil];
    
    if ([NSJSONSerialization isValidJSONObject:tempDic])
    {
        NSError *error;
        NSData *registerData = [NSJSONSerialization dataWithJSONObject:tempDic options:NSJSONWritingPrettyPrinted error:&error];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:registerData];
        [request setPostBody:tempJsonData];
        NSLog(@"Register JSON:%@",[[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding]);
        request.tag = 2;
        [request setDelegate:self];
        [request startAsynchronous];
    }
}

//自动放号
- (void)postAutoRegistInfoWithUserName:(NSString *)username andPassWord:(NSString *)password andDev:(NSString *)dev andDeviceCode:(NSString *)deviceCode andDevPassword:(NSString *)devPassword
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/tnserver/device",netUrlStr]];
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"Content-Type" value:@"text/json; encoding=utf-8"];
    [request addRequestHeader:@"Accept" value:@"text/json"];
    
    [request setRequestMethod:@"PUT"];
    [request setUsername:@"wrt"];
    [request setPassword:@"wrt12"];
    
    NSMutableDictionary *autoRegistDic = [[NSMutableDictionary alloc] init];
    [autoRegistDic setObject:username forKey:@"userName"];
    [autoRegistDic setObject:password forKey:@"password"];
    [autoRegistDic setObject:dev forKey:@"dev"];
    [autoRegistDic setObject:deviceCode forKey:@"deviceCode"];
    [autoRegistDic setObject:devPassword forKey:@"devPassword"];
    
    NSDictionary *tempDic = [[NSDictionary alloc] initWithObjectsAndKeys:autoRegistDic, @"autoregister" , nil];
    
    if ([NSJSONSerialization isValidJSONObject:tempDic])
    {
        NSError *error;
        NSData *registerData = [NSJSONSerialization dataWithJSONObject:tempDic options:NSJSONWritingPrettyPrinted error:&error];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:registerData];
        [request setPostBody:tempJsonData];
        NSLog(@"Register JSON:%@",[[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding]);
        request.tag = 3;
        [request setDelegate:self];
        [request startAsynchronous];
    }
}

//重设密码
- (void)postReSetPasswordWithUserName:(NSString *)username andPassWord:(NSString *)password andVerification:(NSString *)verification
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/tnserver/app",netUrlStr]];
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"Content-Type" value:@"text/json; encoding=utf-8"];
    [request addRequestHeader:@"Accept" value:@"text/json"];
    
    [request setRequestMethod:@"PUT"];
    [request setUsername:@"wrt"];
    [request setPassword:@"wrt12"];
    
    NSMutableDictionary *resetPasswordDic = [[NSMutableDictionary alloc] init];
    [resetPasswordDic setObject:username forKey:@"userName"];
    [resetPasswordDic setObject:password forKey:@"password"];
    [resetPasswordDic setObject:verification forKey:@"verification"];
    
    NSDictionary *tempDic = [[NSDictionary alloc] initWithObjectsAndKeys:resetPasswordDic, @"resetPassword" , nil];
    
    if ([NSJSONSerialization isValidJSONObject:tempDic])
    {
        NSError *error;
        NSData *registerData = [NSJSONSerialization dataWithJSONObject:tempDic options:NSJSONWritingPrettyPrinted error:&error];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:registerData];
        [request setPostBody:tempJsonData];
        NSLog(@"Register JSON:%@",[[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding]);
        request.tag = 5;
        [request setDelegate:self];
        [request startAsynchronous];
    }
}


//验证码获取
- (void)postGetCheckCodeWithUserName:(NSString *)userName
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/tnserver/app/ver",netUrlStr]];
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"Content-Type" value:@"text/json; encoding=utf-8"];
    [request addRequestHeader:@"Accept" value:@"text/json"];
    
    [request setRequestMethod:@"POST"];
    [request setUsername:@"wrt"];
    [request setPassword:@"wrt12"];
    
    NSMutableDictionary *getCheckCodeDic = [[NSMutableDictionary alloc] init];
    [getCheckCodeDic setObject:userName forKey:@"telephone"];
    
    NSDictionary *tempDic = [[NSDictionary alloc] initWithObjectsAndKeys:getCheckCodeDic, @"verification" , nil];
    
    if ([NSJSONSerialization isValidJSONObject:tempDic])
    {
        NSError *error;
        NSData *registerData = [NSJSONSerialization dataWithJSONObject:tempDic options:NSJSONWritingPrettyPrinted error:&error];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:registerData];
        [request setPostBody:tempJsonData];
        NSLog(@"Register JSON:%@",[[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding]);
        request.tag = 4;
        [request setDelegate:self];
        [request startAsynchronous];
    }
}

//设备绑定
- (void)postBindingGatewayDeviceCode:(NSString *)deviceCode andDevicePassword:(NSString *)devicePassword andDeviceType:(NSString *)deviceType andDeviceName:(NSString *)deviceName andUserName:(NSString *)userName andPasssword:(NSString *)password
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/tnserver/device",netUrlStr]];
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"Content-Type" value:@"text/json; encoding=utf-8"];
    [request addRequestHeader:@"Accept" value:@"text/json"];
    
    [request setRequestMethod:@"POST"];
    [request setUsername:@"wrt"];
    [request setPassword:@"wrt12"];
    
    NSMutableDictionary *autoRegistDic = [[NSMutableDictionary alloc] init];
    [autoRegistDic setObject:deviceCode forKey:@"deviceCode"];
    [autoRegistDic setObject:devicePassword forKey:@"devicePassword"];
    [autoRegistDic setObject:deviceType forKey:@"deviceType"];
    [autoRegistDic setObject:userName forKey:@"userName"];
    [autoRegistDic setObject:password forKey:@"password"];
    [autoRegistDic setObject:deviceName forKey:@"deviceName"];
    
    NSDictionary *tempDic = [[NSDictionary alloc] initWithObjectsAndKeys:autoRegistDic, @"bind" , nil];
    
    if ([NSJSONSerialization isValidJSONObject:tempDic])
    {
        NSError *error;
        NSData *registerData = [NSJSONSerialization dataWithJSONObject:tempDic options:NSJSONWritingPrettyPrinted error:&error];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:registerData];
        [request setPostBody:tempJsonData];
        NSLog(@"Register JSON:%@",[[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding]);
        request.tag = 6;
        [request setDelegate:self];
        [request startAsynchronous];
    }
}

//云备份上传
- (void)postCloudBackupWithUserName:(NSString *)userName andPassWord:(NSString *)password andDev:(NSString *)dev andDeviceCode:(NSString *)deviceCode andFilepath:(NSString *)filePath
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/tnserver/cloud",netUrlStr]];
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"Content-Type" value:@"text/json; encoding=utf-8"];
    [request addRequestHeader:@"Accept" value:@"text/json"];
    
    [request setRequestMethod:@"POST"];
    [request setUsername:@"wrt"];
    [request setPassword:@"wrt12"];
    
    NSMutableDictionary *cloudBackupDic = [[NSMutableDictionary alloc] init];
    [cloudBackupDic setObject:userName forKey:@"userName"];
    [cloudBackupDic setObject:password forKey:@"password"];
    [cloudBackupDic setObject:dev forKey:@"dev"];
    [cloudBackupDic setObject:deviceCode forKey:@"deviceCode"];
    [cloudBackupDic setObject:filePath forKey:@"filePath"];
    
    
    NSDictionary *tempDic = [[NSDictionary alloc] initWithObjectsAndKeys:cloudBackupDic, @"backup" , nil];
    
    if ([NSJSONSerialization isValidJSONObject:tempDic])
    {
        NSError *error;
        NSData *registerData = [NSJSONSerialization dataWithJSONObject:tempDic options:NSJSONWritingPrettyPrinted error:&error];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:registerData];
        [request setPostBody:tempJsonData];
        NSLog(@"Register JSON:%@",[[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding]);
        request.tag = 7;
        [request setDelegate:self];
        [request startAsynchronous];
    }
}

//云备份查询
- (void)postCloudQueryWithUserName:(NSString *)userName andPassWord:(NSString *)password andDev:(NSString *)dev andDeviceCode:(NSString *)deviceCode
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/tnserver/cloud",netUrlStr]];
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"Content-Type" value:@"text/json; encoding=utf-8"];
    [request addRequestHeader:@"Accept" value:@"text/json"];
    
    [request setRequestMethod:@"PUT"];
    [request setUsername:@"wrt"];
    [request setPassword:@"wrt12"];
    
    NSMutableDictionary *cloudBackupDic = [[NSMutableDictionary alloc] init];
    [cloudBackupDic setObject:userName forKey:@"userName"];
    [cloudBackupDic setObject:password forKey:@"password"];
    [cloudBackupDic setObject:dev forKey:@"dev"];
    [cloudBackupDic setObject:deviceCode forKey:@"deviceCode"];
    
    NSDictionary *tempDic = [[NSDictionary alloc] initWithObjectsAndKeys:cloudBackupDic, @"search" , nil];
    
    if ([NSJSONSerialization isValidJSONObject:tempDic])
    {
        NSError *error;
        NSData *registerData = [NSJSONSerialization dataWithJSONObject:tempDic options:NSJSONWritingPrettyPrinted error:&error];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:registerData];
        [request setPostBody:tempJsonData];
        NSLog(@"Register JSON:%@",[[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding]);
        request.tag = 8;
        [request setDelegate:self];
        [request startAsynchronous];
    }
}

/**
 *  获取绑定设备的列表
 *
 *  @param userName 用户名（不可空）
 *  @param password 密码（不可空）
 */
- (void)postBindingListWithUserName:(NSString *)userName andPassWord:(NSString *)password
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/tnserver/user/device",netUrlStr]];
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"Content-Type" value:@"text/json; encoding=utf-8"];
    [request addRequestHeader:@"Accept" value:@"text/json"];
    
    [request setRequestMethod:@"POST"];
    [request setUsername:@"wrt"];
    [request setPassword:@"wrt12"];
    
    NSMutableDictionary *getBindDic = [[NSMutableDictionary alloc] init];
    [getBindDic setObject:userName forKey:@"userName"];
    [getBindDic setObject:password forKey:@"password"];
    
    
    NSDictionary *tempDic = [[NSDictionary alloc] initWithObjectsAndKeys:getBindDic, @"getBind" , nil];
    
    if ([NSJSONSerialization isValidJSONObject:tempDic])
    {
        NSError *error;
        NSData *registerData = [NSJSONSerialization dataWithJSONObject:tempDic options:NSJSONWritingPrettyPrinted error:&error];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:registerData];
        [request setPostBody:tempJsonData];
        NSLog(@"Register JSON:%@",[[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding]);
        request.tag = 9;
        [request setDelegate:self];
        [request startAsynchronous];
    }
}

/**
 *  添加绑定
 *
 *  @param userName       用户名（不可空）
 *  @param password       密码（不可空）
 *  @param deviceCode     设备ID
 *  @param devicePassword 设备密码
 *  @param deviceType     设备类型
 *  @param deviceName     设备自定义名称
 *  @param dev            设备名称
 */
- (void)postBindExtensionWithUserName:(NSString *)userName andPassWord:(NSString *)password andDeviceCode:(NSString *)deviceCode andDevicePassword:(NSString *)devicePassword andDeviceType:(int)deviceType andDeviceName:(NSString *)deviceName andDev:(NSString *)dev
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/tnserver/device",netUrlStr]];
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"Content-Type" value:@"text/json; encoding=utf-8"];
    [request addRequestHeader:@"Accept" value:@"text/json"];
    
    [request setRequestMethod:@"POST"];
    [request setUsername:@"wrt"];
    [request setPassword:@"wrt12"];
    
    NSMutableDictionary *bindExtensionDic = [[NSMutableDictionary alloc] init];
    [bindExtensionDic setObject:userName forKey:@"userName"];
    [bindExtensionDic setObject:password forKey:@"password"];
    [bindExtensionDic setObject:deviceCode forKey:@"deviceCode"];
    [bindExtensionDic setObject:devicePassword forKey:@"devicePassword"];
    [bindExtensionDic setObject:[NSNumber numberWithInt:0] forKey:@"deviceType"];
    [bindExtensionDic setObject:deviceName forKey:@"deviceName"];
    [bindExtensionDic setObject:dev forKey:@"dev"];
    
    NSDictionary *tempDic = [[NSDictionary alloc] initWithObjectsAndKeys:bindExtensionDic, @"bind" , nil];
    
    if ([NSJSONSerialization isValidJSONObject:tempDic])
    {
        NSError *error;
        NSData *registerData = [NSJSONSerialization dataWithJSONObject:tempDic options:NSJSONWritingPrettyPrinted error:&error];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:registerData];
        [request setPostBody:tempJsonData];
        NSLog(@"Register JSON:%@",[[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding]);
        request.tag = 10;
        [request setDelegate:self];
        [request startAsynchronous];
    }
}

//解除绑定
- (void)postUnBindExtensionWithUserName:(NSString *)userName andPassWord:(NSString *)password andDeviceCode:(NSString *)deviceCode andDevicePassword:(NSString *)devicePassword
{
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/tnserver/device",netUrlStr]];
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request addRequestHeader:@"Content-Type" value:@"text/json; encoding=utf-8"];
    [request addRequestHeader:@"Accept" value:@"text/json"];
    
    
    [request setUsername:@"wrt"];
    [request setPassword:@"wrt12"];
    
    NSMutableDictionary *unbindExtensionDic = [[NSMutableDictionary alloc] init];
    [unbindExtensionDic setObject:userName forKey:@"userName"];
    [unbindExtensionDic setObject:password forKey:@"password"];
    [unbindExtensionDic setObject:deviceCode forKey:@"deviceCode"];
    [unbindExtensionDic setObject:devicePassword forKey:@"devicePassword"];
    
    
    
    NSDictionary *tempDic = [[NSDictionary alloc] initWithObjectsAndKeys:unbindExtensionDic, @"unbind" , nil];
    
    if ([NSJSONSerialization isValidJSONObject:tempDic])
    {
        NSError *error;
        NSData *registerData = [NSJSONSerialization dataWithJSONObject:tempDic options:NSJSONWritingPrettyPrinted error:&error];
        NSMutableData *tempJsonData = [NSMutableData dataWithData:registerData];
        
        
        
//        [request setPostBody:tempJsonData];
        
        NSLog(@"Register JSON:%@",[[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding]);
        
//        [request addRequestHeader:@"unbind" value:@"{\"unbind\" : {\"password\" : \"12345678\",\"devicePassword\" : \"888888\",\"userName\" : \"13632534929\",\"deviceCode\" : \"0000004603\"}}"];
        
        NSString *tempJsonStr = [[NSString alloc] initWithData:tempJsonData encoding:NSUTF8StringEncoding];
        NSString * responseString = tempJsonStr;
        responseString = [responseString stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
        responseString = [responseString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
        responseString = [responseString stringByReplacingOccurrencesOfString:@"\t" withString:@""];
        [request addRequestHeader:@"unbind" value:responseString];
//        [request addRequestHeader:@"unbind" value:[tempJsonData description]];
        
        
        
        
//        [request buildPostBody];
        request.tag = 11;
        [request setRequestMethod:@"DELETE"];
        [request setDelegate:self];
        [request buildPostBody];
        [request startAsynchronous];
    }
}

#pragma mark -
#pragma mark ASIHttpRequest

- (void)requestFinished:(ASIHTTPRequest *)request
{
    //    // 当以二进制形式读取返回内容时用这个方法
    //    NSData *responseData = [request responseData];
    NSString *respondString = [request responseString];
    NSLog(@"%@",respondString);
    NSDictionary *jsonDic = [self getResponseDicWithRespondStr:respondString];
    NSString *tempCodeStr = [jsonDic objectForKey:@"status"];
    int tempCode = [tempCodeStr intValue];
    NSString *tempString = [jsonDic objectForKey:@"result"];
    if (tempCode == 0)
    {
        if (_delegate != nil && [_delegate respondsToSelector:@selector(postFailedWithString:withTag:)])
        {
            [_delegate postFailedWithString:tempString withTag:request.tag];
        }
    }
    else if (tempCode == 1)
    {
        if (_delegate != nil && [_delegate respondsToSelector:@selector(postSuccessfulWithString:withTag:)])
        {
            [_delegate postSuccessfulWithString:jsonDic withTag:request.tag];
        }
    }
    else if (tempCode == 2 || tempCode == 3)
    {
        if (_delegate != nil && [_delegate respondsToSelector:@selector(postFailedWithString:withTag:)])
        {
            [_delegate postFailedWithString:tempString withTag:request.tag];
        }
    }
}


- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
    NSLog(@"%@",error);
    
    if (_delegate != nil && [_delegate respondsToSelector:@selector(postFailedWithString:withTag:)])
    {
        [_delegate postFailedWithString:@"请求失败请检查网络是否连接正确" withTag:request.tag];
    }
}

- (void)authenticationNeededForRequest:(ASIHTTPRequest *)request
{
    NSLog(@"1111");
}

#pragma mark - 去除制表符
//去除制表符
- (NSDictionary *)getResponseDicWithRespondStr:(NSString *)respondStr
{
    //去除制表符等 防止JSON解析错误
    NSString * responseString = respondStr;
    responseString = [responseString stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
    responseString = [responseString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    responseString = [responseString stringByReplacingOccurrencesOfString:@"\t" withString:@""];
    NSData *data = [responseString dataUsingEncoding:NSUTF8StringEncoding];
    
    //解析
    NSError *error=nil;
    NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
    if(error)
    {
        NSLog(@"%@,%i",error,error.code);
    }
    
    return dict;
}
@end
